<template>
	<view class="page">
		<view class="uni-header uhead">
			<view class="uni-group">
				<uni-easyinput class="left" prefixIcon="search" v-model="query" placeholder="搜索联系人" @confirm="search"
					@iconClick="search"></uni-easyinput>
			</view>
		</view>
		<uni-list class="uhead" :border="false">
			<uni-list-item :title="department" :ellipsis="0" :ltextclass="0" />
		</uni-list>
		<view class="container" v-show="userData!=''||departmentData!=''">
			<uni-list :border="true" v-if="userData">
				<uni-list-item v-for="(item, index) in userData" :key="index" showArrow
					:thumb="item.avatar?convertAvatar(item.avatar):'/static/txl/ico_logo_@3x.png'" thumb-size="base"
					:title="item.userName" :ellipsis="0" :note="item.phone" :ntextclass="1" :clickable="true"
					@click="handleItemClick(item.wxUserId)" />
			</uni-list>
			<uni-list :border="false" v-if="departmentData">
				<uni-list-item v-for="(item, index) in departmentData" :key="index" :leftText="item.percount"
					:ltextclass="0" :rtextclass="0" showArrow :title="item.name" :ellipsis="0" :clickable="true"
					@click="depClick(item.id,item.name)" />
			</uni-list>
		</view>
	</view>
</template>

<script>
	import {
		listDept
	} from '@/api/dept.js'
	import {
		pageWxUserInfo
	} from '@/api/user.js'
	export default {
		data() {
			return {
				loading: '',
				hasMore: '',
				department: '查询结果',
				roleType:'',
				percount: '',
				departmentData: [],
				userData: [],
				department_id: '',
				pic: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/460d46d0-4fcc-11eb-8ff1-d5dcf8779628.png',
				query: '',
				where: '',
				qwhere: '',
				loadMore: {
					contentdown: '',
					contentrefresh: '',
					contentnomore: ''
				}
			}
		},
		onLoad(param) {
			this.department = param.name
			this.roleType = param.roleType
			this.getDepartment(param.id)
			this.getUser(param.id)
		},
		onPullDownRefresh() {},
		onReachBottom() {},
		methods: {
			convertAvatar(avatar){
				return avatar.replace('http://localhost:18000/manage',getApp().globalData.baseUrl)
			},
			async getDepartment(id) {
				// var res = null;
				// try {
				// 	res = await listDept({
				// 		data: {
				// 			parentId: id
				// 		}
				// 	});
				// 	this.departmentData = res.data

				// } catch (err) {

				// }
			},
			async getUser(id) {
				var res = null;
				try {
					res = await pageWxUserInfo({
						params: {
							deptName: this.department=='拍摄' || this.department == '后期'?this.department: '',
							roleType: this.roleType
						},
						page:{
							pageNum: 1,
							pageSize: 100,
						}
					});
					this.userData = res.data.list
				} catch (err) {
				
				}
			},
			back() {
				uni.navigateBack({})
			},
			search() {
				this.$store.state.departmentInfo = {}
				const query = this.query.trim()
				if (!query) {
					query = ''
				}
				uni.redirectTo({
					url: './list2?search=true&query=' + query
				})
			},
			loadData(clear = true) {},
			depClick(department_id, name) {
				uni.navigateTo({
					url: '/pages/contact/contact_sub?id='+department_id+'&name='+name
				})
			},
			handleItemClick(id) {
				uni.navigateTo({
					url: './detail?id=' + id + '&department='+this.department
				})
			}
		}
	}
</script>

<style>
	.load-more {
		background-color: #F7F8FA;
	}
</style>